import os.path
import sys
import re
-from getopt import getopt
+import getopt
import socket
import warnings
warnings.filterwarnings('ignore', category=FutureWarning)
import console
+
+# getopt.gnu_getopt is better, but only exists in Python 2.3+. Use
+# getopt.getopt if gnu_getopt is not available. This will mean that options
+# may only be specified before positional arguments.
+if not hasattr(getopt, 'gnu_getopt'):
+ getopt.gnu_getopt = getopt.getopt
+
+
# Strings for shorthelp
console_help = "console <DomId> Attach to domain DomId's console."
create_help = """create [-c] <ConfigFile>
use_long = 0
show_vcpus = 0
try:
- (options, params) = getopt(args, 'lv', ['long','vcpus'])
- except GetoptError, opterr:
+ (options, params) = getopt.gnu_getopt(args, 'lv', ['long','vcpus'])
+ except getopt.GetoptError, opterr:
err(opterr)
sys.exit(1)
def xm_vnet_list(args):
from xen.xend.XendClient import server
try:
- (options, params) = getopt(args, 'l', ['long'])
- except GetoptError, opterr:
+ (options, params) = getopt.gnu_getopt(args, 'l', ['long'])
+ except getopt.GetoptError, opterr:
err(opterr)
sys.exit(1)
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#============================================================================
# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
+# Copyright (C) 2005 XenSource Ltd.
#============================================================================
"""Object-oriented command-line option support.
"""
-from getopt import getopt, GetoptError
+import getopt
import os
import os.path
import sys
while args:
# let getopt parse whatever it feels like -- if anything
try:
- (xvals, args) = getopt(args[0:],
- self.short_opts(), self.long_opts())
- except GetoptError, err:
+ (xvals, args) = getopt.getopt(args[0:],
+ self.short_opts(),
+ self.long_opts())
+ except getopt.GetoptError, err:
self.err(str(err))
for (k, v) in xvals: